package com.webfinal.backsystem.controller;

import com.webfinal.backsystem.request.product.AddProductRequest;
import com.webfinal.backsystem.request.product.QueryProductRequest;
import com.webfinal.backsystem.request.product.UpdateProductRequest;
import com.webfinal.backsystem.response.product.AddProductResponse;
import com.webfinal.backsystem.response.product.ProductInfoResponse;
import com.webfinal.backsystem.response.product.UpdateProductResponse;
import com.webfinal.backsystem.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/api/product/getproductinfo")
    public ProductInfoResponse getProductInfo(@RequestBody QueryProductRequest request) {
        return productService.queryProduct(request);
    }

    @RequestMapping(value = "/api/product/updateproduct")
    public UpdateProductResponse addproduct(@RequestBody UpdateProductRequest updateProductRequest) {
        UpdateProductResponse response = productService.updateProduct(updateProductRequest);
        return response;
    }

    @RequestMapping(value = "/api/product/addproduct")
    public AddProductResponse addproduct(@RequestBody AddProductRequest addProductRequest) {
        AddProductResponse response = productService.addProduct(addProductRequest);
        return response;
    }

    @RequestMapping(value = "/api/product/uploadimage")
    public AddProductResponse upload(MultipartFile image){
        AddProductResponse response =new AddProductResponse();
        response = productService.coverUpload(image);
        return response;
    }

}
